package com.gmall.jdk8;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StreamTest3 {

    public static void main(String[] args) {

       /* Long a = 1L;
        System.out.println(a.equals(1L));
        //Interger ,short ,Long -128 到 127 之间为true
        //==  比较  对于基本类型，比较的是值。对于引用类型，比较的是地址
        Long b = 200L;
        Long c = 200L;
        System.out.println(c==b);//-128 到 127 之间为true*/

        /**
         *  1 山西           0
         *  2     运城       1
         *  4        临猗    2
         *  5        永济    2
         *  3     长治       1
         *  6        沁县    3
         *  7        武乡    3
         *  8 河南           0
         */
        List<CityEntity> list = new ArrayList<>();
        list.add(new CityEntity(1,0,"山西"));
        list.add(new CityEntity(2,1,"运城"));
        list.add(new CityEntity(3,1,"长治"));
        list.add(new CityEntity(4,2,"临猗"));
        list.add(new CityEntity(5,2,"永济"));
        list.add(new CityEntity(6,3,"沁县"));
        list.add(new CityEntity(7,3,"武乡"));
        list.add(new CityEntity(8,0,"河南"));

        //selct * from city
        List<City> collect = list.stream().filter((a2) -> {
            return a2.getParentId().equals(0);
        }).map((a3) ->{
            City city = new City();
            city.setId(a3.getId());
            city.setName(a3.getName());
            city.setParentId(a3.getParentId());
            city.setChildren(getCityByParentId(list,a3.getId()));

            return city;
        }).collect(Collectors.toList());

        collect.forEach(a1->{
            System.out.println(a1);
        });
    }

    public static List<City> getCityByParentId(List<CityEntity> list,Integer parentId){
        return list.stream().filter((a->{
            return a.getParentId().equals(parentId);
        })).map((a3)->{
            City city = new City();
            city.setId(a3.getId());
            city.setName(a3.getName());
            city.setParentId(a3.getParentId());
            city.setChildren(getCityByParentId(list,a3.getId()));
            return city;
        }).collect(Collectors.toList());
    }




}
